<?php
/**
 * This file is part of DomFg.
 * 
 * DomFg is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * DomFg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with DomFg.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @link http://inditel.ee/
 * @copyright 2007-2009 Inditel Meedia OÜ
 * @author Oliver Leisalu <oliver@inditel.ee>
 */

/**
* @author Oliver Leisalu, Inditel Meedia
* @package DomFg
*/
class DomFgHistory {
	
	const SESSION_VAR = 'domfghistory';
	
	const BACK_VAR = 'domFgBack';
	
	private static $initialized = false;
	
	public static function init() {
		
		if( self::$initialized === true )
			return;
		else
			self::$initialized = true;
		
		if( isset($_SESSION[SESSION_VAR]) )
			$_SESSION[SESSION_VAR] = array();
		
		if( isset($_GET['domFgBack']) ) {
			$_SESSION[SESSION_VAR][] = $_GET['domFgBack'];
		}
		
	}
	
	public static function hasHistory() {
		return !empty($_SESSION[SESSION_VAR]);
	}
	
	public static function goBack() {
		$last = array_pop($_SESSION[SESSION_VAR]);
		goToUrl( $last );
	}
	
	public static function getBackUrlPart( $url ) {
		return '&'.self::BACK_VAR.'='.url_encode($url);
	}
	
	
}
?>